package com.example.yls.demoa;

import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;

public class MainActivity extends AppCompatActivity {
private LinearLayout linearLayout;
private BottomSheetBehavior<LinearLayout> bottomSheetBehavior;
private Button btn1;
private boolean  isboolean =false;
private static final String TAG = "MainActivity";
private TextView textView1;
private TextView textView2;
private TextView textView3;
private TextView textView4;
private BottomNavigationBar bottomNavigationBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        bottomSheetBehaviorEvent();
        btn1Event();
        textView1Event();
        textView2Event();
        textView3Event();
        textView4Event();
        bottomNavigationBarinit();

    }

    private void bottomNavigationBarinit() {

      bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.up,"A"));
      bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.up,"B"));
      bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.up,"C"));
      bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.up,"D"));
    bottomNavigationBar.initialise();
      bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.SimpleOnTabSelectedListener(){
          @Override
          public void onTabSelected(int position) {
              super.onTabSelected(position);
              switch (position){
                  case 0:
                      Toast.makeText(MainActivity.this, "A", Toast.LENGTH_SHORT).show();
                      break;
                  case 1:
                      Toast.makeText(MainActivity.this, "B", Toast.LENGTH_SHORT).show();
                      break;
                  case 2:
                      Toast.makeText(MainActivity.this, "C", Toast.LENGTH_SHORT).show();
                      break;
                  case 3:
                      Toast.makeText(MainActivity.this, "D", Toast.LENGTH_SHORT).show();
                        break;
              }
                    }
      });





    }

    private void textView1Event() {
             textView1.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
                     Toast.makeText(MainActivity.this, "tv1 is click", Toast.LENGTH_SHORT).show();
                 }
             });
    }
    private void textView2Event() {
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "tv2 is click", Toast.LENGTH_SHORT).show();
            }
        });
    }
    private void textView3Event() {
        textView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "tv3 is click", Toast.LENGTH_SHORT).show();
            }
        });
    }
    private void textView4Event() {
        textView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "tv4 is click", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void btn1Event() {

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               /* if (isboolean){
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                }
                else {
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                }
                isboolean=!isboolean;*/
               /* BottomSheetDialog bottomSheetDialog=new BottomSheetDialog(MainActivity.this);
                bottomSheetDialog.setContentView(R.layout.poem);
                bottomSheetDialog.show();*/

      new MybottomDialogFrament().show(getSupportFragmentManager(),"poem");


            }
        });
    }

    private void bottomSheetBehaviorEvent() {
        bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                Log.e(TAG, "newState: "+newState);
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                Log.e(TAG, "slideOffset: "+slideOffset );
            }
        });

    }

    private void initView() {

        linearLayout=findViewById(R.id.bottom_sheet);
        bottomSheetBehavior=BottomSheetBehavior.from(linearLayout);
        btn1=findViewById(R.id.btn1);
        textView1=findViewById(R.id.tv1);
        textView2=findViewById(R.id.tv2);
        textView3=findViewById(R.id.tv3);
        textView4=findViewById(R.id.tv4);
        bottomNavigationBar=findViewById(R.id.id_bnb);

    }
}
